#include "shtc3.h"

//读取温湿度
esp_err_t shtc3_get_temp_hum(float *temp, float *hum)
{
    esp_err_t ret = 0;
    uint16_t temp_data;
    uint16_t hum_data;
    uint8_t SHT3_DATA[6] = {0};
    uint8_t MEAR[2] = {0x5c, 0x24};
    uint8_t WEAKUP[2] = {0x35, 0x17};
    uint8_t SLEEP[2] = {0xb0, 0x98};
    ret |= hal_i2c_write(I2C_MODE_MASTER, SHT3_ADDR, WEAKUP, 2);//唤醒命令
    vTaskDelay(1/portTICK_PERIOD_MS);
    ret |= hal_i2c_write(I2C_MODE_MASTER, SHT3_ADDR, MEAR, 2);//测量命令
    ret |= hal_i2c_read(I2C_MODE_MASTER, SHT3_ADDR, SHT3_DATA, 6);//读取测量结果
    ret |= hal_i2c_write(I2C_MODE_MASTER, SHT3_ADDR, SLEEP, 2);//睡眠命令
    hum_data = (SHT3_DATA[0]<<8)|SHT3_DATA[1];
    temp_data = (SHT3_DATA[3]<<8)|SHT3_DATA[4];
    *temp = (temp_data*175.0)/65536-45;
    *hum = (hum_data*100.0)/65536;
    return ret;
}